﻿using System.Collections.Generic;
using Bookvar.ObjectModel;
using Bookvar.ObjectModel.Collections;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Bookvar.UnitTests.ObjectModel
{
    /// <summary>
    /// Tests for the <see cref="MindMap"/> class.
    /// </summary>
    [TestClass]
    public class MindMapTests
    {
        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext { get; set; }

        #region Additional test attributes

        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //

        #endregion

        [TestMethod]
        public void GetAllTopicsEnumerator_ReturnsAnEnumerator()
        {
            var mindMap = new MindMap();
            IEnumerable<Topic> topicEnumerator = mindMap.GetAllTopics();

            Assert.IsNotNull( topicEnumerator );
        }

        [TestMethod]
        public void GetAllTopics_ReturnsAnEnumeratorThatIteratesOverAllTopics()
        {
            var floatingTopic1 = new Topic();
            var floatingTopic2 = new Topic();
            var mainTopic = new MainTopic();
            var topic1 = new Topic();
            var topic2 = new Topic();

            var allTopics = new TopicCollection { floatingTopic1, floatingTopic2, mainTopic, topic1, topic2 };
            var floatingTopicCollection = new TopicCollection { floatingTopic1, floatingTopic2 };

            mainTopic.SubTopics = new TopicCollection( mainTopic ) { topic1, topic2 };

            var mindMap = new MindMap { FloatingTopics = floatingTopicCollection, MainTopic = mainTopic };

            foreach ( Topic topic in mindMap.GetAllTopics() )
            {
                Assert.IsTrue( allTopics.Contains( topic ) );
                allTopics.Remove( topic );
            }

            Assert.IsTrue( allTopics.Count == 0 );
        }
    }
}